package com.wdz;


import cn.hutool.http.HttpUtil;

import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import com.wdz.elasticsearch.entity.Article;
import com.wdz.music.entity.Music;

import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

public class Test {
    public static void main(String[] args) throws IOException {
       /* try {
            System.out.println(System.getProperty("user.name"));

            //执行批处理文件
            Process process = Runtime.getRuntime().exec("runas /profile /user:Administrator \"cmd.exe /c sc stop mysql");

            //取得命令结果的输出流
            InputStream fis = process.getInputStream();
            //用一个读输出流类去读
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
            String line = null;
            //逐行读取输出到控制台
            while ((line = br.readLine()) != null) {
                System.out.println(new String(line.getBytes(StandardCharsets.UTF_8),"GBK"));
            }

        } catch (IOException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }*/
        /*String result1= HttpUtil.get("https://apps.game.qq.com/cmc/cross?serviceId=3&source=gw_101glzx&tagids=1911,1286&typeids=1,2&limit=10&start=10&logic=and");
        JSONObject jsonObject = JSON.parseObject(result1);

        System.out.println(jsonObject);*/
       /* Article a = new Article();
        a.setDesc("pp");
        Class<?> c = a.getClass();
        Method[] methods = c.getMethods();

        Field[] fields = c.getDeclaredFields();
        System.out.println(fields.length);
        System.out.println(c.getSimpleName());
        Arrays.stream(fields).iterator().forEachRemaining(method ->{
            System.out.println((method.getType()).getSimpleName());
            if((method.getName()).equals("desc")) {
                method.setAccessible(true);
                try {
                    System.out.println(method.get(a));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }

            }
        });*/
        /*int[] nums = {4,4,7,6,7};
        int a;
        int b=0;
        int c=0;
        int[] r = new int[2];
        for(int i=0;i<nums.length;i++){
            a = 0;
            b = 0;
            for(int j=i+1;j<nums.length;j++){
                a = nums[i]+nums[j];
                for(int k=0;k<nums.length;k++){
                    if(k !=i && k != j){
                        b = b+nums[k];
                    }
                }
                System.out.println(a);
                System.out.println(b);
                if(a>b && a>c){
                    r[0] = nums[i];
                    r[1] = nums[j];
                    c = a;
                }
            }
        }
        List<Integer> l = new ArrayList<>();
        for(int i:r){
            l.add(i);
            System.out.println(i);
        }*/
        /*String result1= HttpUtil.get("http://119.29.56.176:3000/playlist/track/all?id=8030329652");
        JSONObject jsonObject = JSON.parseObject(result1,JSONObject.class);
        List<Map<String,Object>> list = jsonObject.get("songs",List.class);
        List<Music> musics = new ArrayList<>();
        for(Map<String,Object> map:list){
            Music music = new Music();
            List<Map<String,Object>> list1 = (List<Map<String, Object>>) map.get("ar");
            Map<String,Object> map1 = list1.get(0);
            music.setArtist(map1.get("name").toString());
            Map<String,Object> map2 = (Map<String, Object>) map.get("al");
            music.setCover(map2.get("picUrl").toString());
            music.setId(Long.valueOf(map.get("id").toString()));
            String result2= HttpUtil.get("http://119.29.56.176:3000/song/url?id="+map.get("id").toString());
            JSONObject jsonObject1 = JSON.parseObject(result2,JSONObject.class);
            List<Map<String,Object>> list2 = jsonObject1.get("data",List.class);
            Map<String,Object> map3 = list2.get(0);
            music.setUrl(map3.get("url").toString());
            music.setFee(Integer.parseInt(map.get("fee").toString()));
            music.setName(map.get("name").toString());
            System.out.println(music.toString());
            musics.add(music);
        }*/
        String result1= HttpUtil.get("https://www.fkcoder.com/myip");
        String result2= HttpUtil.get("https://www.fkcoder.com/ip?ip="+result1);
        JSONObject jsonObject = JSON.parseObject(result2,JSONObject.class);
        //jsonObject = jsonObject.get("data", JSONObject.class);
        System.out.println(jsonObject.toString());
    }
}
